package com.luther.design.singleton;

import java.io.ObjectStreamException;

/**
 * 静态内部类
 * <h3>Description</h3>
 * TODO
 * <h3>Author</h3> luzhenbang
 * <h3>Date</h3> 03/04/2018 12:51
 * <h3>Copyright</h3> Copyright (c)2018 Shenzhen TL  Co., Ltd. Inc. All rights reserved.
 */
public class SingletonFac {
    /**
     * 构造方法私有化
     * */
    private  SingletonFac(){
    }

    public static SingletonFac getInstance() {
        return SingletonFactory.singleton;
    }

    public static  class  SingletonFactory {
        private static SingletonFac singleton  = new SingletonFac();
    }

    /**
     * 杜绝单例对象被反序列化时重新生成对象
     * @return
     * @throws ObjectStreamException
     */
    private Object readResolve() throws ObjectStreamException {
        return getInstance();
    }

}
